package functions

import (
	k8sfunctions "k8s_gui_client/functions/k8s"
	k8sfunctions_config "k8s_gui_client/functions/k8s/config"
	k8sfunctions_network "k8s_gui_client/functions/k8s/network"
	k8sfunctions_storage "k8s_gui_client/functions/k8s/storage"
	k8sfunctions_workload "k8s_gui_client/functions/k8s/workload"
	k8sclient "k8s_gui_client/k8s/client"

	"github.com/zserge/lorca"
)

// bind functions
func Bind(ui lorca.UI) {
	//namespace列表
	ui.Bind("k8s_GetNamespaces", k8sfunctions.GetNamespaces)
	//节点列表
	ui.Bind("k8s_GetNodes", k8sfunctions.GetNodes)

	ui.Bind("k8s_ExportNodeReports", k8sfunctions.ExportNodeReports)
	//节点列表
	ui.Bind("k8s_GetNodes", k8sfunctions.GetNodes)

	ui.Bind("k8s_GetNodeYaml", k8sfunctions.GetNodeYaml)
	//节点监控指标
	ui.Bind("k8s_GetNodeMetrics", k8sfunctions.GetNodeMetrics)

	//事件列表列表
	ui.Bind("k8s_GetEvents", k8sfunctions.GetEvents)

	BindWorkloadFuncitons(ui)

	BindConfigFuncitons(ui)

	BindNetworkFuncitons(ui)

	BindStorageFuncitons(ui)
}

func BindWorkloadFuncitons(ui lorca.UI) {
	//Pod列表
	ui.Bind("k8s_GetPods", k8sfunctions_workload.GetPods)

	//pod监控指标
	ui.Bind("k8s_GetPodMetrics", k8sfunctions_workload.GetPodMetrics)
	//Deployment列表
	ui.Bind("k8s_GetDeployments", k8sfunctions_workload.GetDeployments)
	//DaemonSet
	ui.Bind("k8s_GetDaemonSets", k8sfunctions_workload.GetDaemonSets)
	//StatefulSet
	ui.Bind("k8s_GetStatefulSets", k8sfunctions_workload.GetStatefulSets)
	//Job
	ui.Bind("k8s_GetJobs", k8sfunctions_workload.GetJobs)
	//CronJob
	ui.Bind("k8s_GetCronJobs", k8sfunctions_workload.GetCronJobs)

	//Pod列表
	ui.Bind("k8s_GetPodYaml", k8sfunctions_workload.GetPodYaml)
	//Deployment列表
	ui.Bind("k8s_GetDeploymentYaml", k8sfunctions_workload.GetDeploymentYaml)
	//DaemonSet
	ui.Bind("k8s_GetDaemonSetYaml", k8sfunctions_workload.GetDaemonSetYaml)
	//StatefulSet
	ui.Bind("k8s_GetStatefulSetYaml", k8sfunctions_workload.GetStatefulSetYaml)
	//Job
	ui.Bind("k8s_GetJobYaml", k8sfunctions_workload.GetJobYaml)
	//CronJob
	ui.Bind("k8s_GetCronJobYaml", k8sfunctions_workload.GetCronJobYaml)

	ui.Bind("k8s_GetPodLog", k8sfunctions_workload.GetPodLog)
	ui.Bind("k8s_GetPodPreviousLog", k8sfunctions_workload.GetPodPreviousLog)
	ui.Bind("k8s_OpenPodShell", k8sfunctions_workload.OpenPodShell)
	ui.Bind("k8s_ExportPodReports", k8sfunctions_workload.ExportPodReports)
}

func BindConfigFuncitons(ui lorca.UI) {
	//Configmap列表
	ui.Bind("k8s_GetConfigmaps", k8sfunctions_config.GetConfigmaps)
	//Secret列表
	ui.Bind("k8s_GetSecrets", k8sfunctions_config.GetSecrets)
	//ResourceQuota列表
	ui.Bind("k8s_GetResourceQuotas", k8sfunctions_config.GetResourceQuotas)
	ui.Bind("k8s_ExportResourceQuotaReports", k8sfunctions_config.ExportResourceQuotaReports)
	ui.Bind("k8s_GetLimitRanges", k8sfunctions_config.GetLimitRanges)
	//Configmap列表
	ui.Bind("k8s_GetConfigmapYaml", k8sfunctions_config.GetConfigmapYaml)
	//Secret列表
	ui.Bind("k8s_GetSecretYaml", k8sfunctions_config.GetSecretYaml)
	//ResourceQuota列表
	ui.Bind("k8s_GetResourceQuotaYaml", k8sfunctions_config.GetResourceQuotaYaml)
	//LimitRange列表
	ui.Bind("k8s_GetLimitRangeYaml", k8sfunctions_config.GetLimitRangeYaml)
	//配置文件路径设置
	ui.Bind("k8s_SetConfigPath", k8sclient.SetConfigPath)
	ui.Bind("k8s_GetCurrentConfigPath", k8sclient.GetCurrentConfigPath)
	//文件对话框
	ui.Bind("k8s_OpenFileDialog", OpenFileDialog)
}

func BindNetworkFuncitons(ui lorca.UI) {
	//Service列表
	ui.Bind("k8s_GetServices", k8sfunctions_network.GetServices)
	//Ingress列表
	ui.Bind("k8s_GetIngresses", k8sfunctions_network.GetIngresses)

	//Service列表
	ui.Bind("k8s_GetServiceYaml", k8sfunctions_network.GetServiceYaml)
	//Ingress列表
	ui.Bind("k8s_GetIngressYaml", k8sfunctions_network.GetIngressYaml)
}

func BindStorageFuncitons(ui lorca.UI) {
	ui.Bind("k8s_GetStorageClasses", k8sfunctions_storage.GetStorageClasses)
	ui.Bind("k8s_GetStorageClassYaml", k8sfunctions_storage.GetStorageClassYaml)

	ui.Bind("k8s_GetPersistentVolumeClaims", k8sfunctions_storage.GetPersistentVolumeClaims)
	ui.Bind("k8s_GetPersistentVolumeClaimYaml", k8sfunctions_storage.GetPersistentVolumeClaimYaml)
	ui.Bind("k8s_GetPersistentVolumeClaimStatus", k8sfunctions_storage.GetPersistentVolumeClaimStatus)

	ui.Bind("k8s_GetPersistentVolumes", k8sfunctions_storage.GetPersistentVolumes)
	ui.Bind("k8s_GetPersistentVolumeYaml", k8sfunctions_storage.GetPersistentVolumeYaml)

}
